import path from "path";
import { fileURLToPath } from "url";
import { queryUser } from "../dao/pageDao1.js";


const pathUser = new Map();

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.join(path.dirname(__filename), '../');


function carTable(req, res) {

    queryUser(function (result) {
      let name = req.query.userName;
      let password = req.query.passwd;
      console.log(name + "\t" + password);
      console.log(result);
      let resultMsg = 'fail';
      result.forEach(element=>{
        if (element.User == name && element.pwd == password){
            resultMsg = 'success';
        } 
      })
      console.log(resultMsg);
      let resultJson = {
        data: resultMsg
      };
      res.writeHead(200);
      res.write(JSON.stringify(resultJson));
      res.end();
    });
  }
   pathUser.set('/carTable', carTable);
  export { pathUser };
  